package com.yolo.aim.yoloaim.util;

import ai.djl.modality.cv.output.BoundingBox;
import ai.djl.modality.cv.output.DetectedObjects;
import ai.djl.modality.cv.output.Rectangle;

import java.util.ArrayList;
import java.util.List;

public class DetectedObjectUtil {
    private static DetectedObjectUtil instance;
    public static DetectedObjectUtil me() {
        if (instance == null) {
            instance = new DetectedObjectUtil();
        }
        return instance;
    }


    public DetectedObjects getDetectedObjects(DetectedObjects detection){
        List<String> className=new ArrayList<>();
        List<Double> probability=new ArrayList<>();
        List<BoundingBox> boundingBoxes=new ArrayList<>();
        for (DetectedObjects.DetectedObject obj : detection.<DetectedObjects.DetectedObject>items()) {
            BoundingBox bbox = obj.getBoundingBox();
            Rectangle rectangle = bbox.getBounds();
            className.add(obj.getClassName()+" " + obj.getProbability());
            probability.add(obj.getProbability());
            Rectangle rectangleNew=new Rectangle(rectangle.getX(),rectangle.getY(),
                    rectangle.getWidth(),rectangle.getHeight());
            boundingBoxes.add(rectangleNew);
        }
        return new DetectedObjects(className,probability,boundingBoxes);
    }

}
